package com.itchen.hospital.exception;


import com.itchen.hospital.Msg.TokenExceptionInfo;
import com.itchen.hospital.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.context.request.WebRequest;

@ControllerAdvice(basePackages="com.itchen.hospital.controller")
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    //统一异常处理@ExceptionHandler,主要用于Exception
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(WebRequest request , Exception e){
        log.error("异常信息：",e);
        return Result.error(TokenExceptionInfo.SystemException);
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public Result customError(WebRequest request , CustomException e){
        return Result.error(e.getMsg());
    }
}
